Imports MIMS.WRS.Business
Imports MIMS.WRS.Entities
Imports MyFramework

Public Class BOReportHeader
    Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents ddlOwner As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlType As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlTarget As System.Web.UI.WebControls.DropDownList
    Protected WithEvents btnOK As System.Web.UI.WebControls.Button
    Protected WithEvents btnExportPDF As System.Web.UI.WebControls.LinkButton
    Protected WithEvents txtDiscount As System.Web.UI.WebControls.TextBox
    Protected WithEvents chkShowFOB As System.Web.UI.WebControls.CheckBox
    Protected WithEvents txtQty As System.Web.UI.WebControls.TextBox
    Protected WithEvents chkNotAvailInUSA As System.Web.UI.WebControls.CheckBox
    Protected WithEvents ddlConPoint As System.Web.UI.WebControls.DropDownList
    Protected WithEvents hidSupplierCode As System.Web.UI.HtmlControls.HtmlInputHidden

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Public Event OKClick(ByVal conPointID As Int32, ByVal suppCode As String, ByVal owner As Int32, ByVal type As Int32, ByVal target As Int32, ByVal discount As Decimal, ByVal showFOB As Boolean, ByVal qty As Integer, ByVal notAvailInUSA As Boolean)
    Public Event ExportPDFClick()

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AjaxPro.Utility.RegisterTypeForAjax(GetType(MIMS_WRS.Web.AjaxUtilMethod))

        btnOK.Attributes("onclick") = "collectData();"

        If Not IsPostBack Then
            Me.ddlOwner.DataSource = OfficeService.GetOffices(OfficeColumns.OfficeID, OrderDirection.ASC)
            Me.ddlOwner.DataTextField = OfficeColumns.OfficeName.ToString()
            Me.ddlOwner.DataValueField = OfficeColumns.OfficeID.ToString()
            Me.ddlOwner.DataBind()
            Me.ddlOwner.Items.Insert(0, New ListItem("[All]", "-1"))

            Try
                ddlOwner.SelectedIndex = ddlOwner.Items.IndexOf(ddlOwner.Items.FindByValue(RequestContext.Owner.ToString()))
            Catch ex As Exception

            End Try

            Me.ddlConPoint.DataSource = ConPointService.GetConPoints(ConPointColumns.ConPointID, MyFramework.OrderDirection.ASC)
            Me.ddlConPoint.DataTextField = ConPointColumns.Description.ToString()
            Me.ddlConPoint.DataValueField = ConPointColumns.ConPointID.ToString()
            Me.ddlConPoint.DataBind()
            Me.ddlConPoint.Items.Insert(0, New ListItem("[All]", "-1"))

            Try
                ddlConPoint.SelectedIndex = ddlConPoint.Items.IndexOf(ddlConPoint.Items.FindByValue(RequestContext.ConPointID.ToString()))
            Catch ex As Exception
            End Try

            'Me.ddlSupplier.DataSource = SupplierService.GetSuppliers(RequestContext.ConPointID)
            'Me.ddlSupplier.DataTextField = SupplierColumns.SupplierName.ToString()
            'Me.ddlSupplier.DataValueField = SupplierColumns.SupplierCode.ToString()
            'Me.ddlSupplier.DataBind()
            'Me.ddlSupplier.Items.Insert(0, New ListItem("[All]", ""))
            'Try
            '    ddlSupplier.SelectedIndex = ddlSupplier.Items.IndexOf(ddlSupplier.Items.FindByValue(RequestContext.SupplierCode))
            'Catch ex As Exception

            'End Try

            Dim boType As Int32 = -1
            If Not Request.QueryString("type") Is Nothing Then
                boType = RequestContext.BOType
            End If

            Dim target As Int32 = -1
            If Not Request.QueryString("target") Is Nothing Then
                target = RequestContext.Target
            End If
            Try
                ddlType.SelectedIndex = ddlType.Items.IndexOf(ddlType.Items.FindByValue(boType.ToString()))
            Catch ex As Exception

            End Try

            Try
                ddlTarget.SelectedIndex = ddlTarget.Items.IndexOf(ddlTarget.Items.FindByValue(target.ToString()))
            Catch ex As Exception

            End Try

            txtQty.Text = RequestContext.Quantity.ToString()

            txtDiscount.Text = Request("discount")
            chkShowFOB.Checked = Convert.ToBoolean(Convert.ToInt32(Request("showfob")))
            chkNotAvailInUSA.Checked = RequestContext.NotAvailInUSA
        End If

    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim discount As Decimal = 0
        Try
            discount = Decimal.Parse(txtDiscount.Text)
        Catch ex As Exception
        End Try

        Dim qty As Integer = 0
        Try
            qty = Convert.ToInt32(txtQty.Text)
        Catch ex As Exception
        End Try

        RaiseEvent OKClick(Int32.Parse(ddlConPoint.SelectedItem.Value), hidSupplierCode.Value, Int32.Parse(ddlOwner.SelectedItem.Value), _
                    Int32.Parse(ddlType.SelectedItem.Value), Int32.Parse(ddlTarget.SelectedItem.Value), _
                    discount, chkShowFOB.Checked, qty, chkNotAvailInUSA.Checked)
    End Sub

    Private Sub btnExportPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportPDF.Click
        RaiseEvent ExportPDFClick()
    End Sub
End Class
